package helper

import (
	"math/rand"
	"time"
)

const (
	strCharset = "abcdefghijklmnopqrstuvwxyz"
	numCharset = "0123456789"
)

func RandomString(length int) string {
	return randomCustomCharset(strCharset, length)
}

func RandomNumber(length int) string {
	return randomCustomCharset(numCharset, length)
}

func RandomStringAndNumber(length int) string {
	return randomCustomCharset(numCharset+strCharset, length)
}

func randomCustomCharset(charset string, length int) string {
	r := rand.New(rand.NewSource(time.Now().Unix()))

	if len(charset) < length {
		length = len(charset)
	}

	index := r.Perm(len(charset))[:length]
	print(index)

	result := ""
	for k := range index {
		result += string(charset[index[k]])
	}

	return result
}
